package com.ruoyi.part1.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.part1.domain.BodyPart;
import com.ruoyi.part1.service.IBodyPartService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 身体部位分类Controller
 * 
 * @author ruoyi
 * @date 2025-10-10
 */
@RestController
@RequestMapping("/part1")
public class BodyPartController extends BaseController
{
    @Autowired
    private IBodyPartService bodyPartService;

    /**
     * 查询身体部位分类列表
     */
    @RequiresPermissions("part1:part1:list")
    @GetMapping("/list")
    public TableDataInfo list(BodyPart bodyPart)
    {
        startPage();
        List<BodyPart> list = bodyPartService.selectBodyPartList(bodyPart);
        return getDataTable(list);
    }

    /**
     * 导出身体部位分类列表
     */
    @RequiresPermissions("part1:part1:export")
    @Log(title = "身体部位分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BodyPart bodyPart)
    {
        List<BodyPart> list = bodyPartService.selectBodyPartList(bodyPart);
        ExcelUtil<BodyPart> util = new ExcelUtil<BodyPart>(BodyPart.class);
        util.exportExcel(response, list, "身体部位分类数据");
    }

    /**
     * 获取身体部位分类详细信息
     */
    @RequiresPermissions("part1:part1:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bodyPartService.selectBodyPartById(id));
    }

    /**
     * 新增身体部位分类
     */
    @RequiresPermissions("part1:part1:add")
    @Log(title = "身体部位分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BodyPart bodyPart)
    {
        return toAjax(bodyPartService.insertBodyPart(bodyPart));
    }

    /**
     * 修改身体部位分类
     */
    @RequiresPermissions("part1:part1:edit")
    @Log(title = "身体部位分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BodyPart bodyPart)
    {
        return toAjax(bodyPartService.updateBodyPart(bodyPart));
    }

    /**
     * 删除身体部位分类
     */
    @RequiresPermissions("part1:part1:remove")
    @Log(title = "身体部位分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bodyPartService.deleteBodyPartByIds(ids));
    }
}
